package com.example.module_service.device

import android.os.Bundle
import androidx.activity.viewModels
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.example.lib_common.view.entity.CarPayParam
import com.example.lib_base.path.RouterPath
import com.example.lib_common.view.view.BaseMvvmActivity
import com.example.module_service.R
import com.example.module_service.databinding.ActivityCarPayBinding
import com.example.module_service.viewmodel.ServerViewModel
import dagger.hilt.android.AndroidEntryPoint
import java.text.SimpleDateFormat

@AndroidEntryPoint
@Route(path = RouterPath.PATH_CAR_PAY_PAGE)
class CarPayActivity : BaseMvvmActivity<ActivityCarPayBinding>() {

    @Autowired
    @JvmField
    var carCode:String = ""

    private val carPayViewModel:ServerViewModel by viewModels()
    override fun getLayoutId(): Int =R.layout.activity_car_pay

    override fun initViews() {
        ARouter.getInstance().inject(this)
        mDataBinding.carCode.text = carCode
        mDataBinding.carName.text = carCode
        mDataBinding.carTime1.text = "月卡到期时间："+ SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis())
        mDataBinding.carTime2.text = SimpleDateFormat("2026-MM-dd HH:mm:ss").format(System.currentTimeMillis())

        mDataBinding.btnPayCar.setOnClickListener {
            val carPayParam = CarPayParam(
                entryTime = SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis()),
                exitTime = SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis()),
                id = 0,
                parkingDuration = 60,
                parkingSpaceNumber = "A10",
                paymentAmount = 45,
                paymentMethod = 1,
                paymentTime = SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis()),
                paymentType = 1,
                plateNumber = carCode,
                reservationId = 1
            )
            carPayViewModel.getAddCarPay(carPayParam)
        }
        carPayViewModel.getCarPay.observe(this){
            ToastUtils.showLong("缴费成功")
            //ARouter.getInstance().build("/car/CarStopActivity").navigation()
            ARouter.getInstance().build(RouterPath.PATH_CAR_STOP_PAGE).navigation()
        }

    }

    override fun getActivityState(state: Bundle) {

    }

    override fun saveActivityState(outState: Bundle) {

    }

}